// composables/usePages.ts
import type {
  Page,
  PageListResponse,
  CreateResponse,
  UpdateDeleteResponse
} from '~/types'
import { useApi } from '@/composables/useApi';
export const usePages = () => {
  // 获取分页数据
  const getPages = async (
    page: number = 1,
    size: number = 10
  ): Promise<any> => {
    return await useApi('/api/page', {
      method: 'GET',
      query: { page, size }
    })
  }

  // 创建页面
  const createPage = async (
    params: { title: string; content: string }
  ): Promise<CreateResponse> => {
    return await useApi('/api/page', {
      method: 'POST',
      body: params
    })
  }

  // 更新页面
  const updatePage = async (
    params: { id: string | number } & Partial<Pick<Page, 'title' | 'content'>>
  ): Promise<UpdateDeleteResponse> => {
    return await useApi('/api/page', {
      method: 'PUT',
      body: params
    })
  }

  // 删除页面
  const deletePage = async (
    id: string | number
  ): Promise<UpdateDeleteResponse> => {
    return await useApi('/api/page', {
      method: 'DELETE',
      query: { id }
    })
  }

  return {
    getPages,
    createPage,
    updatePage,
    deletePage
  }
}